package com.neusoft.databus.agent.config;

import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WangguanPluginConfiguration {

    @Autowired
    private WangguanPluginProperties properties;

    @SuppressWarnings("rawtypes")
    @Bean("wangguanPoolConfig")
    GenericKeyedObjectPoolConfig wangguanPoolConfig() {
        final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
        config.setJmxEnabled(false);
        config.setMaxTotal(this.properties.getPool().getMaxTotal());
        config.setMaxTotalPerKey(this.properties.getPool().getMaxTotalPerKey());
        config.setBlockWhenExhausted(this.properties.getPool().isBlockWhenExhausted());
        config.setTestOnCreate(this.properties.getPool().isTestOnCreate());
        config.setTestOnBorrow(this.properties.getPool().isTestOnBorrow());
        config.setTimeBetweenEvictionRunsMillis(this.properties.getPool().getTimeBetweenEvictionRunsMillis());
        config.setMinEvictableIdleTimeMillis(this.properties.getPool().getMinEvictableIdleTimeMillis());
        return config;
    }

}
